<?php
    // 接受前端发送过来的数据
    $username = $_GET["username"];
    // 链接数据库
    $conn = mysqli_connect("localhost", "root", "123456", "sbeam");
    // 查询
    $result = mysqli_query($conn, "SELECT * FROM users where username='$username'");
    // 判断有没有查询到内容
    $num = mysqli_num_rows($result);
    if ($num === 0) {
        echo json_encode(array("error" => 0, "data" => "恭喜可以使用"));
    } else {
        echo json_encode(array("error" => 1, "data" => "用户名已被占用"));
    }
?>